import { defineStore } from 'pinia'
import axios from 'axios';
import mockAxios from '../plugins/mock_axios';
import _ from 'lodash';

const myaxios=mockAxios(axios);

export const useTeacherStore = defineStore({

  id: 'teacher',
  state: () => ({
    teacher: {}//{id,name}
  }),
  getters: {
   // doubleCount: (state) => state.counter * 2
  },
  actions: {
/**
 * 根据考勤员id获取考勤员的完整信息
 * @param {*} id 考勤员ID
 */
    async fetchTeacher(id){
      this.teacher.id=id;
      myaxios.get(`/teacher/${id}`,{ r: { id: 1, name: 'lxf' } }).then(r => {
        this.teacher = r;
      //  return this.teacher;
        //TODO 需要查阅资料ejs或者es6ryf，为什么这样的promise不能return this.teacher?

      })
    },
/**
 * 所授全部课程和班级的组合[{courseId:1,courseName:'算法',clazzId:1,clazzName:'软件2202'}]
 * @returns 所授全部课程和班级的组合[{courseId:1,courseName:'算法',clazzId:1,clazzName:'软件2202'}]
 */
    async fetchAllCoursesWithAllClazzesByTeacherId(){
      return myaxios.get(`/teacher/AllCoursesWithAllClazzesByTeacherId/${this.teacher.id}`,{r:
        [{courseId:1,courseName:'算法',clazzId:1,clazzName:'软件2202'}]
      })
    },

/**
 * 根据老师id获取该老师给所有班所有课程的已有班级考勤表，应该倒叙排列
 * @returns 
 */
    async fetchAttendencesByTeacherId(){
      return myaxios.get(`/teacher/attendencesByTeacherId/${this.teacher.id}`,{r:
        [{id:1,startFrom:230211206,hours:3,courseName:'算法',courseId:1,clazzId:1,clazzName:'软件2202',state:'已确认'}
      ]})
    }


  }
})
